package com.scrumtrek.trainings.tdd;

import java.math.BigDecimal;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Calendar;

public class DatabaseUtil {

    private static final String INSERT_ALL_SQLSTATEMENT = "insert into cash year,version_num,summ,operations values(?,?,?,?)";
    private Connection conn;
    private PreparedStatement ps;

    public DatabaseUtil(Connection conn, PreparedStatement _ps) throws SQLException {
        super();

        if (_ps != null) {
            ps = _ps;
        } else {
            ps = conn.prepareStatement(INSERT_ALL_SQLSTATEMENT);
        }

        this.conn = conn;
    }

    public void increaseProfit(BigDecimal dollars) throws SQLException {
        ps.setInt(1, Calendar.getInstance().get(Calendar.YEAR));
        ps.setString(2, "1234");
        ps.setBigDecimal(3, dollars);
    }

    public Connection getConnection() {
        return conn;
    }

    public void setConnection(Connection conn) {
        this.conn = conn;
    }

    public String buildInsertString() {
        return INSERT_ALL_SQLSTATEMENT;
    }

}
